<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>运营弹窗</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
  <style>
  </style>
</head>
<body>

<div class="layui-fluid">

  <div class="layui-card">
    <div class="layui-card-header">
     IP库
    </div>
    <div class="layui-card-body">

      <table id="LAY-pop" lay-filter="LAY-pop"></table>


      <script type="text/html" id="table-useradmin-admin">
        <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-primary layui-border-green layui-btn-xs" href="/quick_app/libIps?id={{d.id}}">查看IP</a>
      </script>

      <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <button class="layui-btn layui-btn-sm" lay-event="add">添加IP库</button>
        </div>
      </script>

    </div>
  </div>
</div>


<script src="/static/layuiadmin/layui/layui.js"></script>

<script>
  layui.config({
    base: '/static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index','table'], function() {
    var $ = layui.$
            , form = layui.form
            , table = layui.table
            , admin = layui.admin;

    //监听搜索
    form.on('submit(LAY-user-back-search)', function (data) {
      var field = data.field;

      //执行重载
      table.reload('LAY-pop', {
        where: field
        ,page: {
          curr: 1  // 将页码重置为第一页
        }
      });
    });

    table.render({
      elem: '#LAY-pop'
      , url: '/quick_app/ipLibs' //模拟接口
      , response: {
        statusCode: 1
      }
      , toolbar: '#toolbarDemo'
      , defaultToolbar: false
      , cols: [[
        {field: 'id', width: 80, title: 'id'}
        , {field: 'title', title: '名称'}
        , {field: 'create_time', title: '创建时间'}
        , {title: '操作', width: 300, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
      ]]
    });



    //监听行工具事件
    table.on('tool(LAY-pop)', function (obj) {
      var data = obj.data;
      if (obj.event === 'edit') {
        layer.prompt({title: '填写IP库名称', formType: 3,  value: data.title}, function(text, index){
          admin.req({
            url: '/quick_app/setIpLib'
            , type: "POST"
            , data: {'title': text, 'id': data.id}
            , done: function (res) {
              layer.msg('保存成功', {icon: 1, time: 2000}, function () {
                table.reload('LAY-pop');
                layer.close(index); //关闭弹层
              });
            }, not_finish: function (res) {
              layer.msg(res.msg);
            }
          });
        });
      }
    });




    //头工具栏事件
    table.on('toolbar(LAY-pop)', function (obj) {
      switch (obj.event) {
        case 'add':
          layer.prompt({title: '填写IP库名称', formType: 3}, function(text, index){
            admin.req({
              url: '/quick_app/setIpLib'
              , type: "POST"
              , data: {'title':text}
              , done: function (res) {
                layer.msg('保存成功', {icon: 1, time: 2000}, function () {
                  table.reload('LAY-pop');
                  layer.close(index); //关闭弹层
                });
              }, not_finish: function (res) {
                layer.msg(res.msg);
              }
            });
          });
          break;
      }
    });
  });
</script>


</body>
</html>

